const { ipcMain, dialog, nativeImage } = require('electron')

const getSource = (mainWindow) => {
  ipcMain.handle('local-capturer', async (event) => {
    dialog.showOpenDialog({
      buttonLabel: '选择',
      properties: ['multiSelections', 'createDirectory', 'openFile', 'openDirectory']
    }).then((result)=> {
      const image = nativeImage.createFromPath(result.filePaths[0])
      mainWindow.webContents.send('set-source', image.toDataURL())
    })
  })
}

module.exports = getSource